rspec集成测试中的会话对象

您所在的位置:网站首页 ruby page objects for capybara connoisseurs rspec集成测试中的会话对象

rspec集成测试中的会话对象

2023-04-22 07:05| 来源: 网络整理| 查看: 265

百度翻译此文   有道翻译此文 问题描述

I am using rspec and capybara for integration testing.

Is their a way to make session objects in request specs?

I have a view page in which I use a session object to check its value to display selective content.

The problem am facing is that I cannot create a session object in request spec. Here is an example of the view:

---content--- --content--

And inside my request spec

session[:role] = "Role" visit my_path

But it throws me an error "undefined method `session' for nil:NilClass".

I also tried looking into creating session objects of capybara.But couldnt find anything.

Is their any workaround for this? I can not find anything related to this, it seems that it is not possible.A little help is really appreciated.

推荐答案

The way you are supposed to do request specs is visit whatever URL the user would normally need to visit in order for that session variable to be set.

I don't know of any other way, other perhaps than setting the session cookie by hand. Capybara.current_session.driver.browser.set_cookie let's you do this but you would have to create the cookie value by hand.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3